<template>
	<view>
		<view class="container">
			<text class="container-text">小马哥速运同城推广政策</text>
		</view>
		<view class="picture">
				<uni-card :is-shadow="false" v-for="(item,index) in list" :key="index">
					<view class="" style="display: flex;margin-top: 10rpx;">
						<view class="text1" style="flex: 1;">
							<image :src="item.url" alt="" style="width:100px; height:100px;margin-left: 15rpx;"/>	
						</view>
						<view class="text2" style="flex: 1;margin-top: 30rpx;">
							<view class="row1">
								<text style="font-size: 16px;font-weight: bold;margin-left: 60rpx;">{{item.name}}</text>		
							</view>
							<view class="row2">
								<text>下单满{{item.number}}单即可获得</text>		
							</view>
							<view class="row2" @click="addOrder(item)">
								<image src="/static/gift.png" alt="" style="width:30px; height:30px; float: right;"/>			
							</view>
						</view>
					</view>	
				</uni-card>
		</view>
		<view >
			<uni-popup ref="popup" type="message">
				<uni-popup-message :type="msgType" :message="'您当前的订单次数是' + count" :duration="2000"></uni-popup-message>
			</uni-popup>
		</view>
	</view>
</template>

<script>
    import {
		userGiftCount
	} from '@/api/user.js'
	export default {
		data() {
			return {
				msgType: 'success',
				count:0,
				list:[{
					name:'垃圾桶',
					url:'/static/lajitong.jpg',
					number:3
				},
				{
					name:'洗脸盆',
					url:'/static/lianpeng.jpg',
					number:4
				},
				{
					name:'跑马凳',
					url:'/static/dengzi.jpg',
					number:5
				}]
			};
		},
		mounted() {
		   
		},
		onShow() {
			const that = this
			userGiftCount({},'get')
			.then((res)=>{
				// console.log(res)
				uni.setStorageSync('user_count',res.data)
				this.count = res.data
				this.$refs.popup.open()
				
			}).catch((err)=>{
				console.log(err)
			})
		},
		methods:{
			addOrder(item){
				if(this.count < item.number){
					uni.showToast({
						title:"兑换次数不足，无法兑换",
						icon:'none'
					})
				}else{
					uni.navigateTo({
						url: '/pages/giveaway/giveaddress/giveaddress?item=' + JSON.stringify(item)
					})
				}
				
			}
		}
	  }
</script>
<style lang="scss">
	.container{
		display: grid;
		place-items: center;
		font-size: 18px;
		font-weight: bold;
	}
</style>
